package st.business.tepth.business.taskallocation.modifytrouble;

import java.util.List;

import st.business.tepth.base.OnDataConvertListener;
import st.shadow.library.ui.recycler.MultipleItemEntity;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-07-24 19:35
 */

public class ModifyTroublePresenter extends ModifyTroubleContract.Presenter {
    private final ModifyTroubleContract.View mView;
    private final ModifyTroubleContract.Model mModel;

    public ModifyTroublePresenter(ModifyTroubleContract.View view) {
        mView = view;
        mModel = new ModifyTroubleModel();
    }

    @Override
    void getTroubleList(String token, int repairId) {
        addDisposable(mModel.getTroubleList(token, repairId,
                new OnDataConvertListener<List<MultipleItemEntity>>() {
                    @Override
                    public void convert(List<MultipleItemEntity> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showData(null);
                        }
                    }
                }));
    }

    @Override
    void modifyTroubleClassification(String token, int repairId, int phenomenonId, int targetSeriesId) {
        addDisposable(mModel.modifyTroubleClassification(token, repairId,
                phenomenonId, targetSeriesId,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (mView != null) {
                            mView.modifySucceed();
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.modifyFailed(msg);
                        }
                    }
                }, new OnDataConvertListener<List<MultipleItemEntity>>() {
                    @Override
                    public void convert(List<MultipleItemEntity> list) {
                        if (mView != null) {
                            mView.showData(list);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showData(null);
                        }
                    }
                }));
    }
}
